import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class anagrama {

    public static void main(String[] args) throws IOException {
       try{
		System.out.println("ingrese la palabra 1");
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String sTexto1 = in.readLine();
		System.out.println("mostrar palabra1:" +sTexto1.length());
        char[] car = sTexto1.toCharArray();
		System.out.println("ingrese la palabra 2");
        BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in));
        String sTexto2 = in1.readLine();
		System.out.println("mostrar palabra2:" +sTexto2.length());
        char[] car2 = sTexto2.toCharArray();
        boolean var = false;
        int i = 0;
		String sCadenaSinBlancos1 = "";
		String sCadenaSinBlancos2 = "";
		for (int x=0; x < sTexto1.length(); x++) {
  			if (sTexto1.charAt(x) != ' '){
    			sCadenaSinBlancos1 += sTexto1.charAt(x);
			}
		}
		String palabra1 = sCadenaSinBlancos1;
		for (int y=0; y < sTexto2.length(); y++) {
  			if (sTexto2.charAt(y) != ' '){
    			sCadenaSinBlancos2 += sTexto2.charAt(y);
			}
		}
		String palabra2 = sCadenaSinBlancos2;
		System.out.println("mostrar palabra1:" +palabra1.length());
		System.out.println("mostrar palabra2:" +palabra2.length());
    	if (palabra1.equals(palabra2)){
			System.out.println("las palabras son iguales, no hay anagrama");
		}
        else{
			if (palabra1.length() == palabra2.length()){ 
				while ((i< car.length) && (!var)) {
                    int j = 0;
                    boolean var2 = false;
                    while ((j< car2.length) && (!var2)){
                        if (car[i] == car2[j]){
							var2 = true;
							//System.out.println("mostrar valor de var2:" +var2);
                        }
                        j++;
                    }
					if (var2 != true){
						//System.out.println("encontro una letra igual");
					//}
					//else{
						var = true;
					}
			        i++;       
                }
				if (var == true){
					System.out.println("no hay anagrama");
				}
				else{
					System.out.println("anagrama encontrado");
				}
		  	}
			else{
				System.out.println("las palabras no tienen la misma longitud");
			}
        }
		}
        catch (Exception e) {
	    System.out.println ("se pudrio todo!: "+e);
		}
    }
}
